package com.group5.onlinegame.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.group5.onlinegame.dao.IGameDao;
import com.group5.onlinegame.entity.Game;
import com.group5.onlinegame.entity.GameRoom;
import com.group5.onlinegame.entity.GameType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.List;

@Service
public class GameService implements IGameService {
    @Resource
    private IGameDao gameDao;

    @Override
    public PageInfo<Game> getList(int page) {
        PageHelper.startPage(page,5,"id asc");
        List<Game> list=gameDao.getList();
        PageInfo<Game> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }
    public PageInfo<GameType> getTypeList(int page) {
        PageHelper.startPage(page,10,"typeid asc");
        List<GameType> list=gameDao.getTypeList();
        PageInfo<GameType> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public List<GameType> getType() {
        List<GameType> list =gameDao.getTypeList();
        return list;
    }

    @Override
    public Game getGameById(int id) {
        Game game=gameDao.getGameById(id);
        return game;
    }

    @Override
    public int addGame(Game game) {
        return gameDao.addGame(game);
    }

    @Override
    public int editGame(Game game) {
        return gameDao.editGame(game);
    }

    @Override
    public int delGame(int id) {
        return gameDao.delGameById(id);
    }

    @Override
    public GameType gameType(int typeid) {
        GameType gameType=gameDao.gameType(typeid);
        return gameType;
    }

    @Override
    public int editGameType(GameType gameType) {
        return gameDao.editGameType(gameType);
    }

    @Override
    public int addGameType(GameType gameType) {
        return gameDao.addGameType(gameType);
    }

    @Override
    public PageInfo<GameRoom> getRoomList(int page) {
        PageHelper.startPage(page,10,"roomid asc");
        List<GameRoom> list=gameDao.getRoomList();
        PageInfo<GameRoom> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public GameRoom checkRoom(int roomid) {
        return gameDao.checkRoom(roomid);
    }

    @Override
    public int editRoom(GameRoom gameRoom) {
        return gameDao.editRoom(gameRoom);
    }

    @Override
    public int delType(Integer typeid) {
        return gameDao.delType(typeid);
    }

    @Override
    public int delRoom(Integer roomid) {
        return gameDao.delRoom(roomid);
    }

    @Override
    public int roomCheck(Integer roomid) {
        return gameDao.roomCheck(roomid);
    }

}
